// TestGPSView.cpp : implementation file
//

#include "stdafx.h"
#include "GStation.h"
#include "TestGPSView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestGPSView

IMPLEMENT_DYNCREATE(CTestGPSView, CFormView)

CTestGPSView::CTestGPSView()
	: CFormView(CTestGPSView::IDD)
{
	//{{AFX_DATA_INIT(CTestGPSView)
	m_gps_v = _T("");
	//}}AFX_DATA_INIT
}

CTestGPSView::~CTestGPSView()
{
}

void CTestGPSView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestGPSView)
	DDX_Text(pDX, IDC_GPS_Value, m_gps_v);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTestGPSView, CFormView)
	//{{AFX_MSG_MAP(CTestGPSView)
	ON_BN_CLICKED(IDC_StartGPSTest, OnStartGPSTest)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestGPSView diagnostics

#ifdef _DEBUG
void CTestGPSView::AssertValid() const
{
	CFormView::AssertValid();
}

void CTestGPSView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestGPSView message handlers

CGStationDoc * CTestGPSView::GetDocument()
{
	return (CGStationDoc * )m_pDocument;
}

void CTestGPSView::OnStartGPSTest() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	unsigned char * buf;
	buf = (unsigned char *)malloc(2);
	INSHEAD * head = (INSHEAD *)buf;
	*head  = TGT_GPSTEST_START;
	doc->cln.OnSendData(buf,2);
	free(buf);
}

void CTestGPSView::OnButton2() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	unsigned char * buf;
	buf = (unsigned char *)malloc(2);
	INSHEAD * head = (INSHEAD *)buf;
	*head  = TGT_GPSTEST_STOP;
	while(doc->cln.OnSendData(buf,2)==false)
	{

	}
	free(buf);
}

void CTestGPSView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	if(doc->msg_GPSTestData_tag ==  true)
	{
		doc->msg_GPSTestData_tag = false;

		CString s;
		char c1 = '\r';
		char c2 = '\n';
		s.Format("GPSState %d %c%c",doc->msg_GPSTestData.GPSState,c1,c2);
		m_gps_v = s;
		s.Format("N_Pos %f %c%c",doc->msg_GPSTestData.N_Pos,c1,c2);
		m_gps_v += s;
		s.Format("E_Pos %f %c%c",doc->msg_GPSTestData.E_Pos,c1,c2);
		m_gps_v += s;
		s.Format("D_Pos %f %c%c",doc->msg_GPSTestData.D_Pos,c1,c2);
		m_gps_v += s;
	}
	UpdateData(false);
	
}
